""""记录手势标准"""
import cv2
import mediapipe as mp
import tools
import distinguish

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)  # 摄像头
mpHands = mp.solutions.hands
hands = mpHands.Hands()  # 手
mpDraw = mp.solutions.drawing_utils

while True:
    ret, img = cap.read()  # 一次循环截一张图
    if ret:
        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)  # imgRGB是一张图片，cv拿到的图是bgr的，转成rgb
        result = hands.process(imgRGB)  # 把这个图片给hands对象处理,result是侦测出来的手
        # print(result.multi_hand_landmarks)#提取手部21个点的坐标

        if result.multi_hand_landmarks:
            """这里拿到了手部坐标"""
            hds_lm = tools.get_landmark( result.multi_hand_landmarks)  # 获取双手所有坐标放入hds_lm
            print("数据", tools.get_dist(hds_lm, 1))
            if len(hds_lm[0])>=21:#手部不全不算
                distinguish.gesture(hds_lm)
                for handLms in result.multi_hand_landmarks:  # handLms是一只手的21点
                    mpDraw.draw_landmarks(img, handLms)  # img:画在img这个图片上，handLms：要画的点

        cv2.imshow('img', img)

    if cv2.waitKey(1) == ord('q'):  # 按q结束摄像头
        break
